package com.shanghai.dateselectdialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 45000460 on 2017/12/19.
 */

public class DateSelectDialog extends DialogFragment {


    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }

    public interface SelectDateListener {
        void getBack(boolean flag);
    }

    public static SelectDateListener mSelectDateListener;

    public static void setmSelectDateListener(SelectDateListener selectDateListener) {
        mSelectDateListener = selectDateListener;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        List<String> years = new ArrayList<>();
        years.add("2016");
        years.add("2017");
        years.add("2018");


        List<String> months = new ArrayList<>();

        for (int i = 1; i <= 12; i++) {
            months.add(i + "");
        }
        final List<String> days = new ArrayList<>();
        for (int i = 1; i <= 30; i++) {
            days.add(i + "");
        }

        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.fragment_dateselect, container);

        WheelView wv_year = (WheelView) view.findViewById(R.id.wv_year);
        WheelView wv_month = (WheelView) view.findViewById(R.id.wv_month);
        final WheelView wv_day = (WheelView) view.findViewById(R.id.wv_day);

        wv_year.setOffset(1);
        wv_year.setItems(years);
        wv_year.setSeletion(2);
        wv_year.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Toast.makeText(getActivity().getApplicationContext(), "selectedIndex:" + selectedIndex + ",item:" + item, Toast.LENGTH_SHORT).show();
            }
        });
        wv_month.setOffset(1);
        wv_month.setItems(months);
        wv_month.setSeletion(2);
        wv_month.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Toast.makeText(getActivity().getApplicationContext(), "selectedIndex:" + selectedIndex + ",item:" + item, Toast.LENGTH_SHORT).show();
                if (selectedIndex == 2) {

                if (days.contains("30")){
                    days.remove("30");
                    wv_day.setSeletion(1);

                }
                }

            }
        });

        wv_day.setOffset(1);
        wv_day.setItems(days);
        wv_day.setSeletion(2);
        wv_day.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Toast.makeText(getActivity().getApplicationContext(), "selectedIndex:" + selectedIndex + ",item:" + item, Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }

    public String commandName;

    public void setCommandName(String name) {
        this.commandName = name;
    }

}
